package com.mofang.ticketing.base.serve.file.controller;

import com.mofang.ticketing.base.serve.file.pojo.response.AttachmentRespDTO;
import com.mofang.ticketing.base.serve.file.service.IAttachmentManageService;
import com.mofang.ticketing.common.core.result.Result;
import com.mofang.ticketing.common.core.urls.base.FileUrl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author LGC
 */
@Api(tags = "文件")
@RestController
public class FileController {

    @Resource
    private IAttachmentManageService attachmentManageService;

    @ApiOperation(value = "文件上传")
    @PostMapping(FileUrl.FILE_UPLOAD)
    @ApiImplicitParam(name = "file", value = "文件上传", required = true, dataType = "MultipartFile", allowMultiple = true, paramType = "query")
    public Result<AttachmentRespDTO> fileUpload(@RequestParam("file") MultipartFile[] file) {
        return Result.success(attachmentManageService.uploadAttachment(file[0]));
    }

}
